<?php
namespace Forms\Validator;

use Pinenut\Form\Validator;

class RecordNotExistsAction extends Validator
{
	protected $defaultErrorMessage = 'Record not exists';

	protected function isValid($value, $params)
	{
		$className = $params['className'];
		$finder = $className::find();
		if (!empty($params['where'])) {
			foreach ($params['where'] as $fieldName => $fieldValue) {
				$finder->where($fieldName, $fieldValue);
			}
		}

		if (!empty($params['whereValue'])) {
			$finder->where($params['whereValue'], $value);
		}

		return !!$finder->count();
	}
}